package br.com.news.business;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IAcessoNoticiaBusiness;
import br.com.news.utils.database.beans.AcessoNoticiaBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IAcessoNoticiaServiceDb;

@Named
public class AcessoNoticiaBusiness  extends GenericBusiness implements IAcessoNoticiaBusiness{
	
	@Inject
	private IAcessoNoticiaServiceDb acessoNoticiaServiceDb;

	@Override
	public List<AcessoNoticiaBean> findAll() throws BusinessException{
		try {
			return acessoNoticiaServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
	}	
	
	@Override
	public List<AcessoNoticiaBean> maisLidasDaSemana(int qntNoticias,int idCategoria) {
		
		if (idCategoria == 0) {
			return acessoNoticiaServiceDb.maisLidasDaSemana(qntNoticias, idCategoria);
		}
		return null;
		
	}
	
	@Override
	public void save(AcessoNoticiaBean acessoNoticiaBean) throws BusinessException {
		try {
			acessoNoticiaServiceDb.save(acessoNoticiaBean);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar salvar a noticia", e);
		}
	}

}
